<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/17
 * Time: 12:51
 */

namespace App\gen;


trait DbGenerator
{
    static $mapType = [
        'int' => 'integer',
        'varchar' => 'string',
        'timestamp' => 'string',
    ];

    public static function formatColmns($colmns){
        foreach ($colmns as $col){
            preg_match('/^[a-z_\-A-Z]+/',$col->Type,$m);
            if(isset( self::$mapType[$m[0]] )){
                $col->show_type = self::$mapType[$m[0]] ;
            }else{
                $col->show_type = 'string' ;
            }

            if($col->Comment == ''){
                $col->Comment = $col->Field ;
            }
        }
        return $colmns ;
    }
}